/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tencent.mavenproject1;

import java.util.Date;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 *
 * @author janksenhu
 */
public class Mail1 {
    public static void main(String[] ar)throws Exception{
        System.setProperty("java.net.useSystemProxies", "false"); 
        //send email use proxy
                Properties props = System.getProperties(); //方式二
                props.setProperty("proxySet", "true");
                props.setProperty("socksProxyHost", "127.0.0.1");   //socke5代理服务器地址
                props.setProperty("socksProxyPort", "8888");

                props.setProperty("mail.smtp.host", "smtp.163.com");
                props.put("mail.smtp.auth", "true");
//                final String username_01 = "hujiangshui"; // 用户名
//                final String password_01 = "hjs312net"; // 密码

//                Session newSession = Session.getInstance(props);
                Session newSession;
                        newSession = Session.getDefaultInstance(props, new Authenticator() {
                    @Override
                    protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
                        return new javax.mail.PasswordAuthentication("hujiangshui", "hjs312net");
                       }
                
                });
                
                
                MimeMessage message = new MimeMessage(newSession);
                InternetAddress from = new InternetAddress("hujiangshui@163.com"); // 发件人邮箱
                message.setFrom(from);
                InternetAddress sto = new InternetAddress("hujiangshui@163.com"); // 收件人邮箱
                message.setRecipient(Message.RecipientType.TO, sto);
                message.setRecipient(Message.RecipientType.CC, sto);
                message.setRecipient(Message.RecipientType.BCC, sto);
               
 
                message.setSentDate(new Date());
 
                
                
                message.setSubject("Test email #");
                message.setContent("This is test email #sent from Hudson Continuous Integration server.", "text/plain");
               
                
              
                Transport transport_01 = newSession.getTransport("smtp");
                transport_01.send(message);

                System.out.println("Message sent.");
    
    
    
    }
}
